home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_13_09
/
letters
/
tick1.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1995-07-17
|
3KB
|
149 lines
//Listing 1: TICK1.CPP
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <time.h>
#define RACK 1
#define ERR if (*err<0)) \
printf("\nError No. %d, \
Address No. %d, \
Command No. %d", *err, \
*add, *com);
int near *err; //ptr to error ret
int near *add; //ptr to optomux adr
int near *com; //ptr to optomux cmd
//pointers to module position in
//optomux rack, modifier array, and
//data return array:
int near modu[16], modi[2], dat[l6];
//initialize rack and variables
void ints(void);
//read inputs
void read_modules(void);
//call the driver
extern "C" void pascal
optoware(int near*, int near*,
int near*, int near*,
int near*, int near*);
// driver
main()
{
int count = 0; //value of scans ctr
//clock ticks at current scan
clock_t curr_time = 0;
//clock ticks at first scan
clock_t start_time = 0;
clrscr();
inits(); // ready sys for startup
//clock ticks at initial scan
start_time = clock();
//loop through 5000 reads
while (count < 5000 && !kbhit()){
read_size();
curr_time
= clock(); // clk ticks now
count+= l; // clock ticks now
}
clrscr();
gotoxy(22, 2);
printf(
"Total ticks for 5000 reads..%ld",
curr_time-start_time);
if (kbhit()) // loop early exit
{
clrscr();
gotoxy(22, 10);
printf("Oops, you hit the ");
printf("boo boo bye bye key!");
gotoxy(1, 1)
}
return 0; // end of function main
}
/********************************/
// ready system for operation
void inits(void)
{
int i; // array variable index
//array variable index
int er = 0, cmd = 102;
int ad = 0; // host address
err= &er;
add = &ad;
com = &cmd;
dat[0] = 3; // set host to com3
//call driver
optoware(err, add, com,
modu, modi, dat);
ERR // error macro
// set host baud rate to 38400
cmd= 104;
dat[0] = 38400;
optoware(err, add, com,
modu, modi, dat);
ERR
//initialize optoware parameters
for (i=0; i<=15; ++i){
modu[i] = 0;
dat[i] = 0;
}
modi[0] = 0;
modi[1] = 0;
//disable power-up clear msg.
cmd = 0;
add = RACK; // for optomux rack
er= 0;
optoware(err, add, com,
modu, modi, dat);
ERR
return;
}
/****************************/
void read_modules(void)
{
int ad_size
= RACK; // at address RACK
// 12 is command to read
int s_cmd = 12;
// reset any previous errors
int s_err = 0;
// point globals to locals
add = &ad_size;
com = &s_cmd;
err = &s_err;
optoware(err, add, com,
modu, modi, dat);
ERR
// For anyone curious to know,
// this program indicates about
// 5.65 millisecond per scan
return;
}